import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/modules/application/education/course_center/integrated_theme/course_detail_detail_page/course_detail/train_introduction/train_introduction_controller.dart';

///课程介绍introduction
class TrainIntroductionPage extends StatelessWidget {
  TrainIntroductionPage({super.key});

  final controller = Get.put(TrainIntroductionController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return SingleChildScrollView(
            child: Container(
              padding: EdgeInsets.all(16.w),
              color: Colors.white,
              child: Column(
                children: [
                  _customWidget(AppImages.icon_train_user_group, '使用人群', value: controller.textbookDetailEntity?.textbookCrowd ?? ''),
                  AppGaps.vGap14,
                  _customWidget(AppImages.icon_train_teacher, '授课老师',
                      widget: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          _topWidget(),
                          _bottomWidget(),
                        ],
                      )),
                  AppGaps.vGap14,
                  _customWidget(AppImages.icon_train_course_overview, '课程概述', value: controller.textbookDetailEntity?.textbookOverview ?? ''),
                  AppGaps.vGap44,
                ],
              ),
            ),
          );
        });
  }

  Widget _customWidget(String svg, String name, {Widget? widget, String? value}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            SvgPicture.asset(svg),
            AppGaps.hGap2,
            Text(
              name,
              style: TextStyle(
                color: const Color(0xFF262F38),
                fontWeight: FontWeight.w500,
                fontSize: 14.sp,
              ),
            ),
          ],
        ),
        AppGaps.vGap8,
        Container(
          padding: EdgeInsets.only(left: 14.w, top: 6.w, right: 14.w, bottom: 6.w),
          width: double.infinity,
          decoration: BoxDecoration(
            color: const Color(0x1A5C6DFF),
            borderRadius: BorderRadius.circular(4.w),
          ),
          child: Align(
            alignment: Alignment.centerLeft,
            child: widget ??
                Text(
                  '$value',
                  style: TextStyle(
                    color: const Color(0xFF495061),
                    fontWeight: FontWeight.w400,
                    fontSize: 12.sp,
                  ),
                ),
          ),
        )
      ],
    );
  }

  Widget _topWidget() {
    return Row(
      children: [
        controller.lecturerDetailEntity == null
            ? SvgPicture.asset(AppImages.icon_train_teacher_bg)
            : Container(
                margin: EdgeInsets.only(top: 8.w, right: 8.w),
                width: 50.w,
                height: 50.w,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(40.w),
                    color: Colors.white,
                    border: Border.all(
                      color: const Color(0xFFEFF2F6),
                      width: 1,
                    ),
                    image: DecorationImage(
                      image: NetworkImage('${Interface.fileUrl}${controller.lecturerDetailEntity?.lecturerHead}'),
                      // image: NetworkImage('${item.lecturerHead}'),
                    )),
              ).clickShowLarge(url: '${controller.lecturerDetailEntity?.lecturerHead}'),
        AppGaps.hGap8,
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Expanded(
                    child: Text(
                      controller.lecturerDetailEntity?.lecturerName ?? '',
                      style: TextStyle(
                        color: const Color(0xFF495061),
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                  ),
                  Text(
                    '更多',
                    style: TextStyle(
                      color: const Color(0xFF5C6DFF),
                      fontSize: 12.sp,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                  AppGaps.hGap4,
                  Obx(
                    () => SvgPicture.asset(controller.showMore.value ? AppImages.icon_train_more : AppImages.icon_train_more_default),
                  )
                ],
              ).clickOnce(() {
                controller.showMore.value = !controller.showMore.value;
              }),
              AppGaps.vGap4,
              Row(
                children: [
                  SvgPicture.asset(AppImages.icon_train_like_),
                  AppGaps.hGap8,
                  Text(
                    '${controller.lecturerDetailEntity?.likeNum ?? ''}',
                    style: TextStyle(
                      color: const Color(0xFFFC9900),
                      fontSize: 14.sp,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ],
              ).clickOnce(controller.onClickTrainLikeTeacher),
            ],
          ),
        ),
      ],
    );
  }

  Widget _bottomWidget() {
    return Obx(() => Visibility(
        visible: controller.showMore.value,
        child: Column(
          children: [
            AppGaps.vGap14,
            Text(
              controller.lecturerDetailEntity?.lecturerProfiles ?? '',
              style: TextStyle(
                color: const Color(0xFF495061),
                fontWeight: FontWeight.w400,
                fontSize: 12.sp,
              ),
            )
          ],
        )));
  }
}
